package com.astar.controller;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import com.astar.config.WxMaConfiguration;
import com.astar.config.WxMaProperties;
import com.astar.domain.UnifiedUserInfo;
import com.astar.dto.WechatInfo;
import com.astar.redis.RedisCacheManager;
import com.astar.service.UserInfoService;
import com.astar.util.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 *
 * 接收小程序过来的请求
 * Created by liuruiyan on 2019/8/25.
 */
@RestController
@RequestMapping("/receive/smallApp")
@Slf4j
public class ReceiveSmallAppReqController extends BaseController{

    @Autowired
    private WxMaProperties wxMaProperties;

    @Autowired
    private RedisCacheManager redisCacheManager;

    @Autowired
    private UserInfoService userInfoService;


    /**
     * 验证消息的确来自微信服务器
     * @param timestamp
     * @param nonce
     * @param signature
     * @param echostr
     * @return
     */
    @RequestMapping("/checkSignature")
    public Object checkSignature(String timestamp, String nonce, String signature,String echostr){

        final WxMaService wxService = WxMaConfiguration.getMaService(wxMaProperties.getAppid());
        Boolean bool = wxService.checkSignature(timestamp,nonce,signature);
        if(bool){
            return echostr;
        }
        return null;
    }

}
